#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from django.utils import simplejson
from model import PostClassM

class getQuestionStatsHandler(webapp.RequestHandler):
    def get(self):
        postClassKey = self.request.get("postClassKey")
        questionKey = self.request.get("questionKey")
        
        if postClassKey and questionKey:
            result = PostClassM.getQuestionStats(postClassKey, questionKey)
            if isinstance(result, basestring): #Error
                self.response.out.write(result)
            elif result:
                self.response.out.write(simplejson.dumps(result))
        else:
            pass

application = webapp.WSGIApplication([(r'.*', getQuestionStatsHandler)],debug=True)

def main():
    run_wsgi_app(application)
    
if __name__ == '__main__':
    main()